package org.cubikalabs.todolist.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.messaging.config.ServerConfig;
	import mx.rpc.IResponder;
	
	import org.cubikalabs.todolist.business.BusinessDelegate;
	import org.cubikalabs.todolist.model.ModelLocator;
	
	public class GetTodoListCommand implements IResponder, ICommand
	{
		public function execute(event:CairngormEvent):void
		{
			new BusinessDelegate(this).getTodoList();
		}

		public function result(data:Object):void
		{
			trace("result get todo list")
			var todoList:ArrayCollection = ModelLocator.getInstance().todoList;
			todoList.removeAll();
			if(data.result && data.result is ArrayCollection)
				todoList.addAll(data.result); 
		}
		
		public function fault(info:Object):void
		{
			Alert.show("fails get todo list")
		}
		
	}
}